package BanyuanClub.Work.Day0224.TeDate;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

/**
 * 生成一个日历
 */
public class TheCalendar {
    public static void main(String[] args) throws ParseException {
//        Scanner in = new Scanner(System.in);
//        String s = in.next();
//        String s = "2021-04-25";
//        System.out.println("日\t一\t二\t三\t四\t五\t六");
//        SimpleDateFormat sp = new SimpleDateFormat("yyyy-MM-dd");
//        Date date = sp.parse(s);
//        Calendar calendar = Calendar.getInstance();
//        calendar.setTime(date);
//        int thedate = calendar.get(Calendar.DATE);
//        calendar.set(Calendar.DATE,1);
//        int dayofweek = calendar.get(Calendar.DAY_OF_WEEK);
//        for (int i = 0; i < dayofweek-1; i++) {
//            System.out.print("\t");
//        }
//        int ofmonth = calendar.getActualMaximum(Calendar.DATE);
//        for (int i = 1; i < ofmonth+1; i++) {
//            if(thedate == i){
//                System.out.print("*");
//            }
//            System.out.print(i+"\t");
//            calendar.set(Calendar.DATE,i);
//            int ia = calendar.get(Calendar.DAY_OF_WEEK);
//            if(ia == Calendar.SATURDAY){
//                System.out.println();
//            }
//        }
//        String s = "2021-04-24";
        System.out.println("请输入日期：yyyy-MM-dd");
        Scanner in = new Scanner(System.in);
        String s = in.next();
        System.out.println("日\t一\t二\t三\t四\t五\t六");
        SimpleDateFormat sp = new SimpleDateFormat("yyyy-MM-dd");
        Date da = sp.parse(s);
        Calendar ca = Calendar.getInstance();
        ca.setTime(da);
//        System.out.println(ca);
        int thisday = ca.get(Calendar.DAY_OF_MONTH);
        int monthdays = ca.getActualMaximum(Calendar.DATE);
//        System.out.println(monthdays);
        ca.set(Calendar.DATE,1);
        int dayofweek = ca.get(Calendar.DAY_OF_WEEK);
        for (int i = 0; i < dayofweek-1; i++) {
            System.out.print("\t");
        }
//        System.out.println(1);
        for (int i = 1; i < monthdays+1; i++) {
            if (thisday == i){
                System.out.print("*");
            }
            System.out.print(i+"\t");
            ca.set(Calendar.DATE,i);
            if (ca.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY){
                System.out.println();
            }
        }
    }
}
